// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import "../Components"

AndroidItem {
    id: _root
    width: 720 * viewScale
    height: 50 * viewScale
    color: "#000000"

    property variant statusBarBackgroundPath: []    //ステータスバーの背景
    property variant statusBarWifiPath: []          //Wifi
    property variant statusBarWifiFullyPath: []     //Wifi fully
    property variant statusBarWifiInOutPath: []     //Wifi in/out
    property variant statusBarBatteryPath: []       //バッテリー
    property variant statusBarBatteryChargePath: [] //バッテリー充電

    property int wifiSignal: 3              //wifiの強度
    property int wifiSignalFully: 3         //wifiの強度 fully
    property bool isWifiSignalFully: false  //wifi fullか
    property int wifiInOut: 0               //wifiの通信方向 0:なし,1:in,2:out
    property int batteryCharge: 5            //バッテリー充電具合
    property bool isBatteryCharge: false    //充電中

    signal clicked(int key)
    signal mouseMove(variant mouse)
    signal pressed(variant mouse)
    signal released(variant mouse)

    //バッテリーの充電状態は割合でくるので変換する
    onBatteryChargeChanged: {
        if(_battery.picts.length > 0){
            _battery.index = (_battery.picts.length - 1) * batteryCharge / 100;
        }
    }
    //wifiもは抜ける可能性があるので
    onWifiSignalChanged: {
        if(_wifiSignal.picts.length > 0){
            _wifiSignal.index = (_wifiSignal.picts.length - 1) * wifiSignal / 4;
        }
    }

    //背景画像
    Image{
        id: _background
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        height: 50 * _root.viewScale
        cache: false
        source: statusBarBackgroundPath[0]
    }

    //ステータスバーのアイコンたち
    //本当はRowを使いたいところだけど何故か重なって表示されているので。
    Item{
        anchors.right: isLock ? _root.right : _clock.left
        anchors.rightMargin: 10 * viewScale
        width: _wifiSignal.width + _3gSignal.width + _battery.width
        height: _root.height
        //wifi
        PictImage{
            id: _wifiSignal
            anchors.verticalCenter: parent.verticalCenter
            x: 4 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 36 * _root.viewScale
            cache: false
            picts: statusBarWifiPath
            states: State{
                when: _root.isWifiSignalFully
                PropertyChanges {
                    target: _wifiSignal
                    picts: statusBarWifiFullyPath
                }
            }
        }
        //wifiの通信方向
        PictImage{
            anchors.verticalCenter: parent.verticalCenter
            x: 4 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 36 * _root.viewScale
            cache: false
            picts: statusBarWifiInOutPath
            index: _root.wifiInOut
        }
        //3G
        Image{
            id: _3gSignal
            anchors.verticalCenter: parent.verticalCenter
            x: 32 * viewScale
            width: 39 * _root.viewScale
            height: 36 * _root.viewScale
            source: "images/SystemUI/stat_sys_signal_null.png"
        }
        //バッテリー
        PictImage{
            id: _battery
            anchors.verticalCenter: parent.verticalCenter
            x: 78 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 36 * _root.viewScale
            cache: false
            picts: statusBarBatteryPath
            states: State{
                when: _root.isBatteryCharge
                PropertyChanges {
                    target: _battery
                    picts: statusBarBatteryChargePath
                }
            }
        }
    }

    ImageClock{
        id: _clock
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        anchors.rightMargin: 10 * viewScale

        visible: !isLock
        clockNumberWidth: 16 * viewScale

        numberPics: new Array("images/bar_num_0.png"
                    , "images/bar_num_1.png"
            , "images/bar_num_2.png"
            , "images/bar_num_3.png"
            , "images/bar_num_4.png"
            , "images/bar_num_5.png"
            , "images/bar_num_6.png"
            , "images/bar_num_7.png"
            , "images/bar_num_8.png"
            , "images/bar_num_9.png"
                    )
        colonPic: "images/bar_num_c.png"
    }

    MouseArea{
        anchors.fill: parent
        onClicked: {
            _root.clicked(0);
        }
        onPressed: {
            _root.pressed(mouse);
        }
        onMousePositionChanged: {
            _root.mouseMove(mouse);
        }
        onReleased: {
            _root.released(mouse);
        }
    }

    states: [
        State {
            name: "Land"
            when: !isPortrait
            PropertyChanges {
                target: _background
                source: _root.statusBarBackgroundPath[1]
            }
        }
    ]
}
